package com.yax.mickey.controller;

import com.yax.mickey.common.result.Result;
import com.yax.mickey.entity.OrderDetail;
import com.yax.mickey.service.OrderDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ResponseBody
@RestController
@RequestMapping("/orderDetail")
@Api(tags = "用户端订单详情相关接口")
@Slf4j
public class OrderDetailController {
    @Autowired
    OrderDetailService orderDetailService;

    @GetMapping("/getAllOrderDetail")
    @ApiOperation("获取所有订单详情信息")
    public Result<List<OrderDetail>> getAllOrderDetail() {
        List<OrderDetail> orderDetailList = orderDetailService.getAllOrderDetail();
        return Result.success(orderDetailList);
    }

    @GetMapping("/getOrderDetailByOrderId/{orderId}")
    @ApiOperation("根据订单ID查询订单详情信息")
    public Result<List<OrderDetail>> getOrderDetailByOrderId(@PathVariable Integer orderId) {
        List<OrderDetail> orderDetailList = orderDetailService.getOrderDetailByOrderId(orderId);
        return Result.success(orderDetailList);
    }

    @PostMapping("/addOrderDetail")
    @ApiOperation("新增订单详情信息")
    public Result<Integer> addOrderDetail(@RequestBody OrderDetail orderDetail) {
        Integer addOrderDetail = orderDetailService.addOrderDetail(orderDetail);
        return Result.success(addOrderDetail);
    }

    @PutMapping("/updateOrderDetail")
    @ApiOperation("更新订单详情信息")
    public void updateOrderDetail(@RequestBody OrderDetail orderDetail) {
        orderDetailService.updateOrderDetail(orderDetail);
    }

    @DeleteMapping("/deleteOrderDetail")
    @ApiOperation("删除订单详情信息")
    public void deleteOrderDetail(@RequestBody OrderDetail orderDetail) {
        orderDetailService.deleteOrderDetail(orderDetail);
    }
}
